package com.coocaa.layerdrawable;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "xl";

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        float scale = getResources().getDisplayMetrics().densityDpi;
        float widthPx = getResources().getDisplayMetrics().widthPixels;
        Log.e(TAG, "densityDpi :" + scale + "widthPX :" + widthPx);
        Drawable d0 = getDrawable(Color.parseColor("#00FFFF"), 0, 0, new float[]{10, 10, 10, 10, 10, 10, 10, 10});
        Drawable d1 = getDrawable(Color.parseColor("#0000FF"), 0, 0, new float[]{10, 10, 10, 10, 10, 10, 10, 10});
        Drawable[] ds = new Drawable[2];
        ds[0] = d0;
        ds[1] = d1;
        LayerDrawable layerDrawable = new LayerDrawable(ds);
        layerDrawable.setLayerWidth(0, 300);
        layerDrawable.setLayerHeight(0, 100);
        layerDrawable.setLayerWidth(1, 100);
        layerDrawable.setLayerHeight(1, 100);

        TextView textView = findViewById(R.id.textView);
        textView.setBackground(layerDrawable);


    }


    public static GradientDrawable getDrawable(int solidColor, int strokeColor, int strokeWidth, float[] radius) {
        GradientDrawable drawable = new GradientDrawable();
        drawable.setColor(solidColor);
        drawable.setStroke(strokeWidth, strokeColor);
        drawable.setCornerRadii(radius);
        return drawable;
    }
}
